/******************************************************************************
	File Name:
		UserAMessage.h
	Description:
		Message System Definition for User A: between A's server and A's Clients.
	History:
		PROGRAMMER		Date			Description			
		Hongqi,Wang		05/31/2009		Original

	Note:
	
******************************************************************************/

#include <SharedMsg.h>

typedef unsigned char UserAMsgVersion;

enum UserAMsgType
	{
	UAMT_QUERY = 0,
	UAMT_UPDATE,
	UAMT_ADD,
	
	UAMT_MAX
	};
	
struct UserARecord
	{
	UInt32 Field1;
	UInt32 Field2;
	UInt32 Field3;
	UInt32 Field4;
	UInt32 Field5;
	
	inline UserARecord ( )
		{
		memset ( this, 0, sizeof(UserARecord) );
		}
	
	};
	
enum UserABits
	{
	UAM_FIELD1_BIT = 0,
	UAM_FIELD2_BIT,
	UAM_FIELD3_BIT,
	UAM_FIELD4_BIT,
	UAM_FIELD5_BIT,
	
	UAM_MAX_BITS
	};
	
	
// This is the generic data transfer message.  The usageBits member
// is a bit map with one bit for each data item.  If the bit is set
// the data item is included when the message is en/decoded.

class UserAMessage : public Message
	{
public:
	static const UInt8 USER_A_MSG_VERSION_INVALID = 0;
	static const UInt8 USER_A_MSG_VERSION_1       = 1;
	static const UInt8 USER_A_MSG_VERSION_2       = 2;
	static const UInt8 USER_A_MSG_CURRENT_VERSION = USER_A_MSG_VERSION_2;
	
	unsigned char version;
	UInt32 usageBits;
	UInt32 msgType;
	GmtTime transTime;
	IBool decodeError;
	UserARecord data;
public:
	UserAMessage ( );
	~UserAMessage ( );
	
	//Set Functions store the value and also set the usage bit.
	void SetField1( UInt32 & value );
	void SetField2( UInt32 & value );
	void SetField3( UInt32 & value );
	void SetField4( UInt32 & value );
	void SetField5( UInt32 & value );
	
	//These functions test wether a field is included
	IBool HasData ( UserABits fieldId );
	
	//Get Functions
	UInt32 Sizeof ( ) const;
	UserAMsgVersion Version ( ) const;
	
	IStatus Encode ( void * buffer, int bufferSize );
	IStatus Decode ( void * buffer, int bufferSize );
	void DecodeHeader ( void * buffer, int bufferSize );
	
private:
	static const UInt32 bitMask[32];
	
	void EncodeHeader ( MessageBuffer & buffer );
	void DecodeHeader ( MessageBuffer & buffer );
	};